#include "widget_main.h"



main_widget::main_widget( QWidget* parent, Qt::WindowFlags flags ): QWidget( parent, flags )
{	
	layout = new QVBoxLayout( this );


	QLabel* title_l = new QLabel( this );
	title_l->setTextFormat( Qt::RichText );
	string title = "<b><font size=8>AI Tester Server " + string( SERVER_VERSION ) + "</font></b>";
	title_l->setText( title.c_str() );
	layout->addWidget( title_l );


	layout->addSpacing( 20 );


	start_b = new QPushButton( "Start Server", this );
	connect( start_b, SIGNAL( clicked() ), this, SLOT( start_server() ) );
	layout->addWidget( start_b );


	layout->addSpacing( 10 );


	about_qt_b = new QPushButton( "About Qt", this );
	connect( about_qt_b, SIGNAL( clicked() ), this, SLOT( about_qt() ) );
	layout->addWidget( about_qt_b );


	about_b = new QPushButton( "About", this );
	connect( about_b, SIGNAL( clicked() ), this, SLOT( about() ) );
	layout->addWidget( about_b );


	exit_b = new QPushButton( "Exit", this );
	connect( exit_b, SIGNAL( clicked() ), this, SLOT( exit() ) );
	layout->addWidget( exit_b );


	this->setLayout( layout );
	//this->setFixedSize( 279, 195 );
};



void main_widget::start_server()
{
	server_gui* sgui = server_gui::get_instance();
	QScrollArea* sa = new QScrollArea( sgui->g );
	sgui->g->setup_w = new setup_widget( sa );
	sa->setWidget( sgui->g->setup_w );
	sa->setWidgetResizable( true );
	sgui->g->main_w->deleteLater();
	sgui->g->main_w = 0;
	sgui->g->setCentralWidget( sa );
	sgui->g->setMinimumSize( 501, 416 );
	sgui->g->resize( 501, 416 );
};



void main_widget::about_qt()
{
	qApp->aboutQt();
};



void main_widget::about()
{
	about_widget* aw = new about_widget( this );
	aw->show();
};



void main_widget::exit()
{
	qApp->quit();
};



about_widget::about_widget( QWidget* parent ): QMessageBox( parent )
{
	setWindowTitle( "AI Tester Server- About" );
	setText( "<h3>About AI Tester Server</h3>" );
	string text = "<p>AI Tester " + string( SERVER_VERSION ) + "</p>"
		"<p>This application is a server for network games with AI Tester.</p>"
		"<p>Works only with AI Tester " + string( CLIENT_VERSION ) + ".</p>"
		"<p>AI Tester Server is licensed under the GNU General Public License version 3.0.</p>"
		"<p>Copyright (C) 2010 Tomas Hubik.</p>";
	setInformativeText( text.c_str() );
	setAttribute( Qt::WA_DeleteOnClose );
	QPixmap icon( "AI_Tester_Server.gif" );
    if ( !icon.isNull() )
        setIconPixmap( icon );
};